# 线上post
import json, ssl
from urllib import request

context = ssl._create_unverified_context()

target_url = 'https://m.ctrip.com/restapi/soa2/18622/queryFuzzyCityList.json'

json_data = {"head":{"cid":"09031156210480907966","ctok":"","cver":"1.0","lang":"01","sid":"8888","syscode":"09","auth":None,"extension":[{"name":"partner","value":"zhixing"},{"name":"aid","value":"30613"},{"name":"sid","value":"1458119"}],"xsid":""},"reqhead":{"protocol":"http:","appid":100019513,"host":"m.ctrip.com","locale":"zh-cn","cury":"cny","channelid":5,"biztype":32,"pttype":17,"ptgroup":17,"sf":"h5","cid":"09031156210480907966","os":"","mode":"web","gps":{},"token":"","wlver":"0.202001171542","stntype":0,"ubt":{"pageid":10650033311,"pvid":162,"sid":23,"vid":"1566972380685.19s445n"},"union":{"sid":"1693366","aid":"66672","ouid":""}},"key":"aa","maxcount":20,"pttype":17,"ptgroup":17}

post_data = json.dumps(json_data)

req = request.Request(target_url)

req.add_header('Content-Type', 'application/json')

with request.urlopen(req, data=post_data.encode('utf-8'), context=context) as content:
    rst_str = content.read().decode()
    rst = json.loads(rst_str)
    print(rst['list'])
    print(len(rst['list']))